package snmyj.agile.tomcatcode.jmx;

import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;

public class Main {
	/*
	 * For simplicity, we declare "throws Exception". Real programs will usually
	 * want finer-grained exception handling.
	 */
	public static void main(String[] args) throws Exception {
		// Get the Platform MBean Server
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

		// Construct the ObjectName for the Hello MBean we will register
		ObjectName mbeanName = new ObjectName("snmyj.agile.tomcatcode.jmx:type=ConnectionNumber");

		// Create the Hello World MBean
		ConnectionNumber mbean = new ConnectionNumber();

		// Register the Hello World MBean
		mbs.registerMBean(mbean, mbeanName);

		// Wait forever
		System.out.println("Waiting for incoming requests...");
		while (true) {
			Thread.sleep(1000);
			System.out.println(mbean.getConnectionNumber());
		}

	}
}
